package com.xinzhidi.web.householdClassify.controller;

import com.xinzhidi.common.annotation.Log;
import com.xinzhidi.common.core.controller.BaseController;
import com.xinzhidi.common.core.domain.AjaxResult;
import com.xinzhidi.common.core.domain.R;
import com.xinzhidi.common.core.page.TableDataInfo;
import com.xinzhidi.common.enums.BusinessType;
import com.xinzhidi.common.utils.poi.ExcelUtil;
import com.xinzhidi.web.householdClassify.dto.HouseholdClassifyAddDto;
import com.xinzhidi.web.householdClassify.dto.HouseholdClassifyListDto;
import com.xinzhidi.web.householdClassify.dto.HouseholdClassifyUpdDto;
import com.xinzhidi.web.householdClassify.service.IHouseholdClassifyService;
import com.xinzhidi.web.householdClassify.vo.HouseholdClassifyInfoVo;
import com.xinzhidi.web.householdClassify.vo.HouseholdClassifyListVo;
import com.xinzhidi.web.plot.domain.vo.SelectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

/**
 * 住户分类Controller
 *
 * @author gm
 * @date 2023-06-09
 */
@RestController
@Api(tags = "住户分类")
@RequestMapping("/householdClassify")
public class HouseholdClassifyController extends BaseController {
    @Autowired
    private IHouseholdClassifyService householdClassifyService;

    @ApiOperation("查询住户分类列表")
    @PreAuthorize("@ss.hasPermi('householdClassify:householdClassify:list')")
    @PostMapping("/listHouseholdClassify")
    public TableDataInfo<HouseholdClassifyListVo> listHouseholdClassify(@Validated @RequestBody HouseholdClassifyListDto dto) {
        startPagePost(dto);
        return householdClassifyService.selectHouseholdClassifyList(dto);
    }

    @ApiOperation("查询住户分类列表")
    @PostMapping("/listHouseholdClassifySelect")
    public TableDataInfo<SelectVo> listHouseholdClassifySelect(@Validated @RequestBody HouseholdClassifyListDto dto) {
        dto.setPageSize(9999);
        startPagePost(dto);
        return householdClassifyService.listHouseholdClassifySelect(dto);
    }




    @ApiOperation("导出住户分类列表")
    @PreAuthorize("@ss.hasPermi('householdClassify:householdClassify:export')")
    @Log(title = "住户分类", businessType = BusinessType.EXPORT)
    @PostMapping("/exportHouseholdClassify")
    public void exportHouseholdClassify(HttpServletResponse response, HouseholdClassifyListDto dto) {
        TableDataInfo<HouseholdClassifyListVo> list = householdClassifyService.selectHouseholdClassifyList(dto);
        ExcelUtil<HouseholdClassifyListVo> util = new ExcelUtil<HouseholdClassifyListVo>(HouseholdClassifyListVo.class);
        util.exportExcel(response, list.getRows(), "住户分类数据");
    }

    @ApiOperation("获取住户分类详细信息")
    @PreAuthorize("@ss.hasPermi('householdClassify:householdClassify:query')")
    @GetMapping(value = "/getHouseholdClassifyById")
    public R<HouseholdClassifyInfoVo> getHouseholdClassifyById(@RequestParam("id") Long id) {
        return R.ok(householdClassifyService.selectHouseholdClassifyById(id));
    }

    @ApiOperation("新增住户分类")
    @PreAuthorize("@ss.hasPermi('householdClassify:householdClassify:add')")
    @Log(title = "住户分类", businessType = BusinessType.INSERT)
    @PostMapping("addHouseholdClassify")
    public AjaxResult addHouseholdClassify(@Validated @RequestBody HouseholdClassifyAddDto dto) {
        return toAjax(householdClassifyService.insertHouseholdClassify(dto));
    }

    @ApiOperation("修改住户分类")
    @PreAuthorize("@ss.hasPermi('householdClassify:householdClassify:edit')")
    @Log(title = "住户分类", businessType = BusinessType.UPDATE)
    @PostMapping("editHouseholdClassify")
    public AjaxResult editHouseholdClassify(@Validated @RequestBody HouseholdClassifyUpdDto dto) {
        return toAjax(householdClassifyService.updateHouseholdClassify(dto));
    }

    @ApiOperation("删除住户分类")
    @PreAuthorize("@ss.hasPermi('householdClassify:householdClassify:remove')")
    @Log(title = "住户分类", businessType = BusinessType.DELETE)
    @DeleteMapping("/delHouseholdClassify")
    public AjaxResult delHouseholdClassify(@RequestParam Long[] ids) {
        return toAjax(householdClassifyService.deleteHouseholdClassifyByIds(ids));
    }

    @ApiOperation("移除住户")
    @PreAuthorize("@ss.hasPermi('householdClassify:householdClassify:remove')")
    @Log(title = "移除住户", businessType = BusinessType.DELETE)
    @DeleteMapping("/moveHouseholdClassify")
    public AjaxResult moveHouseholdClassify(@RequestParam Long id) {
        return toAjax(householdClassifyService.moveHouseholdClassify(id));
    }
}
